package com.zb.mobile.user.controller;

import com.zb.entity.AccounLoginInfo;
import com.zb.exception.VendorIdentifierException;
import com.zb.mobile.user.service.ConUserMobileGoodsService;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjProductService;
import com.zb.utils.TokenUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author WEN
 * @Date 2023/11/5 0005
 **/
@Api(tags = "用户报单移动端商品类接口")
@RestController
@RequestMapping("/mobile/user/gooods")
public class UserGoodsController {
    @Resource
    private ConUserMobileGoodsService conUserMobileGoodsService;
    @Resource
    private ZjProductService productService;

    @ApiOperation("我的商品 - 商品列表")
    @PostMapping("/getGoodsList")
    public Result getGoodsList(HttpServletRequest request, @RequestBody PageUtil pageUtil) {
        Long userId = TokenUserUtil.getAccountIdByToken(request);
        return Result.success().data(conUserMobileGoodsService.getGoodsList(userId, pageUtil));
    }

    @ApiOperation("我的商品 - 商品列表详情")
    @GetMapping("/getGoodsDetail/{codeId}")
    public Result getGoodsDetail(@PathVariable @ApiParam(value = "编码ID", required = true) Long codeId) {
        return Result.success().data("row", conUserMobileGoodsService.getGoodsDetail(codeId));
    }

    @ApiOperation("我的商品 - 商品列表详情-收费标准")
    @PostMapping("/getModuleFeeLis")
    public Result getModuleFeeList(HttpServletRequest request, @RequestBody PageUtil pageUtil) throws VendorIdentifierException {
        Long custAccId = TokenUserUtil.getcustAccIdByToken(request);
        return Result.success().data(conUserMobileGoodsService.getModuleFeeList(custAccId, pageUtil));
    }

    @ApiOperation("我的商品 - 商品列表详情-配件价格")
    @PostMapping("/getSpareFeeList/{codeId}")
    public Result getSpareFeeList(@PathVariable @ApiParam(value = "编码ID", required = true) Long codeId, @RequestBody PageUtil pageUtil) {
        return Result.success().data(conUserMobileGoodsService.getSpareFeeList(codeId, pageUtil));
    }

    @ApiOperation("获取我的报单商品列表")
    @PostMapping("/getUserOrderGoodsList")
    public Result getUserOrderGoodsList(HttpServletRequest request, @RequestBody PageUtil pageUtil) throws VendorIdentifierException {
        AccounLoginInfo loginInfo = TokenUserUtil.getAccountLoginInfo(request);
        if (null == loginInfo) {
            loginInfo = new AccounLoginInfo(0L, "", "", "", "");
            loginInfo.setCustAccId(TokenUserUtil.getCustAccIdByMobildUserCustCode(request));
        }
        return Result.success().data(conUserMobileGoodsService.getUserOrderGoodsList(loginInfo, pageUtil));
    }

    @ApiOperation("根据商品ID取商品参数")
    @GetMapping("/getGoodsParamField/{goodsId}")
    public Result getGoodsParamField(@PathVariable @ApiParam(value = "商品ID", required = true) Long goodsId) {
        return Result.success().data(PageUtil.row(productService.getProductParam(goodsId)));
    }


}
